$(document).ready(function () {

    setTimeout(function () {
        $("#captchaImg").attr("src", "captcha?time=" + Math.random() + new Date().getTime()).fadeIn();
    }, 100);
    $("#captchaImg").click(function () {
        $(this).attr("src", "captcha?time=" + Math.random() + new Date().getTime()).fadeIn();
    });
    var _submit = function () {

        var account = $('#account').val(), pwd = $('#password').val(), code = $('#code').val();
        var url = $("#form1").attr("action");
        //warning
        if ($.trim(account) === "") {
            _toast('warning', '\u8BF7\u8F93\u5165\u8D26\u53F7');
            return;
        }
        if ($.trim(pwd) === "") {
            _toast('warning', '\u8BF7\u8F93\u5165\u5BC6\u7801');
            return;
        }
        if ($.trim(code) === "") {
            _toast('warning', '\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801');
            return;
        }

        $.post(url, {
        	"account": account,
        	"password":new jsSHA(pwd, "ASCII").getHash("SHA-256", "HEX"),
        	"code": code
        }, function(data) {
        	if (data.code === "1") {
        		window.location.href = "center";
        	} else {
        		_toast('error', data.msg);
        	}
        }, "json");
    };
    $("#signIn").click(function () {
        _submit();
    });
    //keydow,keypress,keyup
    $(document).keydown(function (event) {
        if (event.keyCode === 13) {
            _submit();
        }
    });
});